package com.xianyu.us.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.xianyu.us.pojo.entity.UsUser;

/**
 * 用户数据持久层接口
 * @author wangshili
 *
 */
@Mapper
public interface UsUserDao {
	/**
	 * 根据用户名获取用户对象
	 */
	@Select("select * from us_users where username=#{username}")
	UsUser findUserByUserName(String username);
	
	/**
	 * 插入一个用户
	 * @param user 用户对象
	 * @return
	 */
	@Insert("insert into us_users values(null,#{username},#{password},#{salt},#{phone},#{email},#{introduction},now(),now())")
	int insertUser(UsUser user);
	
	/**
	 * 根据用户名查找出现的次数，来判断用户名是否已存在
	 * @param username
	 * @return
	 */
	@Select("select count(*) from us_users where username=#{username}")
	Integer selectUsUserByUsername(String username);
	
	/**
	 * 根据用户id查询 用户信息
	 * @param id
	 * @return
	 */
	@Select("select * from us_users where id=#{id}")
	UsUser selectUsUserById(Integer id);
	
	@Select("select id,username,phone,email,introduction from us_users where username=#{username}")
	UsUser selectByUsername(String username);
	
}
